/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmSpot.java
 *
 * Created on 24/11/2012, 08:56:34 PM
 */
package mumaker.forms;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.io.File;
import java.io.IOException;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import mumaker.Util;
import mumaker.spots.GestGrahSpot;
import mumaker.spots.GestMapa;
import mumaker.spots.GestMob;
import mumaker.spots.GestSpots;
import mumaker.spots.GraphSpots;
import mumaker.spots.Mapa;

/**
 *
 * @author Javs
 */
public class FrmSpot extends javax.swing.JFrame {

    /** Creates new form FrmSpot */
    public FrmSpot() throws IOException {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel5 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        lblCordX = new javax.swing.JLabel();
        lblCordY = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtabelSpots = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        SliderCant = new javax.swing.JSlider();
        jLabel11 = new javax.swing.JLabel();
        lvlCantidad = new javax.swing.JLabel();
        lblRadio = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        SliderRadio = new javax.swing.JSlider();
        jLabel8 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        lblCantMobs = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        lblCantAgregados = new javax.swing.JLabel();
        lblCantMaps = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        lblCantSpots = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtNomMob = new javax.swing.JTextField();
        txtNroMob = new javax.swing.JTextField();
        txtDirec = new javax.swing.JTextField();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jPanel5 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jLabel19 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        txtLimiteRandom = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("MuMaker - SpotMaker By: jpra110 (Sanpu)");
        setResizable(false);
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
                formWindowLostFocus(evt);
            }
        });
        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                formFocusLost(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(51, 51, 51));
        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel1.setMaximumSize(new java.awt.Dimension(501, 501));
        jPanel1.setMinimumSize(new java.awt.Dimension(501, 501));
        jPanel1.setPreferredSize(new java.awt.Dimension(501, 501));
        jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel1MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jPanel1MouseEntered(evt);
            }
        });
        jPanel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jPanel1MouseMoved(evt);
            }
        });
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLayeredPane1.setBackground(new java.awt.Color(153, 102, 255));
        jLayeredPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLayeredPane1MouseClicked(evt);
            }
        });

        jLabel5.setBackground(new java.awt.Color(0, 0, 0));
        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mumaker/img/lore.png"))); // NOI18N
        jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel5MouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel5MouseEntered(evt);
            }
        });
        jLabel5.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                jLabel5MouseMoved(evt);
            }
        });
        jLabel5.setBounds(0, 0, 500, 500);
        jLayeredPane1.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jPanel1.add(jLayeredPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 500, 500));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 501, 501));

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton3.setText("Agregar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 500, 90, 30));

        lblCordX.setFont(new java.awt.Font("Arial", 1, 14));
        lblCordX.setText("0");
        jPanel3.add(lblCordX, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, -1, 20));

        lblCordY.setFont(new java.awt.Font("Arial", 1, 14));
        lblCordY.setText("0");
        jPanel3.add(lblCordY, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 10, -1, 20));

        jLabel4.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel4.setText(" X :");
        jLabel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, 90, 20));

        jLabel6.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel6.setText(" Y :");
        jLabel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel3.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 10, 90, 20));

        jLabel3.setFont(new java.awt.Font("Arial", 1, 14));
        jLabel3.setText("Cordenadas :");
        jPanel3.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, 20));

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 500, 501, 40));

        jtabelSpots.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mob", "Mapa", "Radio", "X", "Y", "X²", "Y²", "Dir", "Cant", "Nombre"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtabelSpots.setRowSelectionAllowed(false);
        jtabelSpots.setShowVerticalLines(false);
        jtabelSpots.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jtabelSpotsPropertyChange(evt);
            }
        });
        jtabelSpots.addVetoableChangeListener(new java.beans.VetoableChangeListener() {
            public void vetoableChange(java.beans.PropertyChangeEvent evt)throws java.beans.PropertyVetoException {
                jtabelSpotsVetoableChange(evt);
            }
        });
        jScrollPane2.setViewportView(jtabelSpots);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 0, 460, 510));

        jButton1.setText("Seleccionar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 300, 120, 20));

        jButton2.setText("Load Mobs");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 0, 90, 30));

        jButton4.setText("Load Maps");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(610, 0, -1, 30));

        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        getContentPane().add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 140, 140, -1));

        jLabel13.setText("Mob :");
        getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 300, -1, 20));

        jLabel12.setText("Direccion :");
        getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 270, -1, 20));

        SliderCant.setMajorTickSpacing(2);
        SliderCant.setMaximum(50);
        SliderCant.setMinimum(1);
        SliderCant.setMinorTickSpacing(2);
        SliderCant.setPaintTicks(true);
        SliderCant.setValue(0);
        SliderCant.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                SliderCantStateChanged(evt);
            }
        });
        getContentPane().add(SliderCant, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 220, 120, 30));

        jLabel11.setText("Valor : ");
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 200, -1, -1));

        lvlCantidad.setText("1");
        getContentPane().add(lvlCantidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 250, 30, 20));

        lblRadio.setText("1");
        getContentPane().add(lblRadio, new org.netbeans.lib.awtextra.AbsoluteConstraints(660, 200, 30, -1));

        jLabel9.setText("Valor :");
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(620, 250, 40, 20));

        SliderRadio.setMajorTickSpacing(2);
        SliderRadio.setMaximum(50);
        SliderRadio.setMinimum(1);
        SliderRadio.setMinorTickSpacing(2);
        SliderRadio.setPaintTicks(true);
        SliderRadio.setValue(1);
        SliderRadio.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                SliderRadioStateChanged(evt);
            }
        });
        SliderRadio.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                SliderRadioCaretPositionChanged(evt);
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        SliderRadio.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                SliderRadioPropertyChange(evt);
            }
        });
        getContentPane().add(SliderRadio, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 170, 120, 30));

        jLabel8.setText("Radio :");
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 170, -1, 30));

        jLabel1.setText("Mapa :");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 140, -1, 20));

        jLabel7.setText("Cantidad :");
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 230, -1, -1));

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel2.setText("Mobs Agregados :");
        jPanel2.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 90, 20));

        lblCantMobs.setText("0");
        jPanel2.add(lblCantMobs, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, 30, 10));

        jLabel14.setText("Cantidad Mapas :");
        jPanel2.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, -1, -1));

        jLabel15.setText("Cantidad Mobs :");
        jPanel2.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        lblCantAgregados.setText("0");
        jPanel2.add(lblCantAgregados, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 70, 30, 20));

        lblCantMaps.setText("0");
        jPanel2.add(lblCantMaps, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 30, 30, -1));

        jLabel10.setText("---------------------------------------");
        jPanel2.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, 10));

        jLabel16.setText("Cantidad Spots :");
        jPanel2.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 90, -1));

        lblCantSpots.setText("0");
        jPanel2.add(lblCantSpots, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 50, 30, -1));

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 40, 180, 90));

        jButton5.setText("Exportar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(1080, 510, 80, 30));

        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel17.setText("Nombre Mob :");
        jPanel4.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        jLabel18.setText("Numero Mob :");
        jPanel4.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        txtNomMob.setEditable(false);
        jPanel4.add(txtNomMob, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, 160, -1));

        txtNroMob.setEditable(false);
        jPanel4.add(txtNroMob, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 160, -1));

        getContentPane().add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 330, 180, 110));

        txtDirec.setText("-1");
        getContentPane().add(txtDirec, new org.netbeans.lib.awtextra.AbsoluteConstraints(570, 270, 120, -1));

        jButton6.setText("Eliminar");
        jButton6.setEnabled(false);
        getContentPane().add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(780, 510, 80, 30));

        jButton7.setEnabled(false);
        getContentPane().add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(740, 510, 40, 30));

        jButton8.setEnabled(false);
        getContentPane().add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 510, 40, 30));

        jProgressBar1.setEnabled(false);
        getContentPane().add(jProgressBar1, new org.netbeans.lib.awtextra.AbsoluteConstraints(860, 510, 220, 30));

        jPanel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Si");
        jPanel5.add(jRadioButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, -1, -1));

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("No");
        jPanel5.add(jRadioButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        jLabel19.setText("Randomizar X ²  Y ²");
        jPanel5.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        jTextField1.setText("0");
        jTextField1.setEnabled(false);
        jPanel5.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 60, 110, 20));

        txtLimiteRandom.setText("5");
        txtLimiteRandom.setEnabled(false);
        jPanel5.add(txtLimiteRandom, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 30, 110, 20));

        getContentPane().add(jPanel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(510, 450, 180, 90));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jPanel1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel1MouseEntered

    private void jPanel1MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MouseMoved
        Point p = new Point(this.jPanel1.getMousePosition().getLocation());
        this.lblCordX.setText(String.valueOf(p.getX() / 2));
        this.lblCordY.setText(String.valueOf(p.getY() / 2));

    }//GEN-LAST:event_jPanel1MouseMoved

    private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel1MouseClicked

    private void SliderRadioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_SliderRadioPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_SliderRadioPropertyChange

    private void SliderRadioCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_SliderRadioCaretPositionChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_SliderRadioCaretPositionChanged

    private void SliderRadioStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_SliderRadioStateChanged
        // TODO add your handling code here:
        this.lblRadio.setText(String.valueOf(SliderRadio.getValue()));
    }//GEN-LAST:event_SliderRadioStateChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        JFileChooser fileopen = new JFileChooser();
        FileFilter filter = new FileNameExtensionFilter("*.txt", "txt");
        fileopen.addChoosableFileFilter(filter);

        int ret = fileopen.showDialog(this, "Open file");

        if (ret == JFileChooser.APPROVE_OPTION) {
            File file = fileopen.getSelectedFile();
            try {
                Util.devolverSpotsTxt(file.getCanonicalPath());
                this.lblCantMobs.setText(String.valueOf(GestMob.getInstance().retornarMob().size()));
            } catch (IOException ex) {
                Logger.getLogger(FrmSpot.class.getName()).log(Level.SEVERE, null, ex);
            }


        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void SliderCantStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_SliderCantStateChanged
        // TODO add your handling code here:
        this.lvlCantidad.setText(String.valueOf(SliderCant.getValue()));
    }//GEN-LAST:event_SliderCantStateChanged

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        JFileChooser fileopen = new JFileChooser();
        FileFilter filter = new FileNameExtensionFilter("*.txt", "txt");
        fileopen.addChoosableFileFilter(filter);

        int ret = fileopen.showDialog(this, "Open file");

        if (ret == JFileChooser.APPROVE_OPTION) {
            File file = fileopen.getSelectedFile();
            try {
                Util.devolverMapas(file.getCanonicalPath());
                this.lblCantMaps.setText(String.valueOf(GestMapa.getInstance().retornarMapas().size()));
            } catch (IOException ex) {
                Logger.getLogger(FrmSpot.class.getName()).log(Level.SEVERE, null, ex);
            }


        }

        //cargamos los mapas al combo.
        for (mumaker.spots.Mapa m : GestMapa.getInstance().retornarMapas()) {
            jComboBox1.addItem(m);
        }

    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:

        FrmMobs m = new FrmMobs(this.txtNroMob, this.txtNomMob);
        m.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jtabelSpotsPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jtabelSpotsPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jtabelSpotsPropertyChange

    private void jtabelSpotsVetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {//GEN-FIRST:event_jtabelSpotsVetoableChange
        // TODO add your handling code here:
    }//GEN-LAST:event_jtabelSpotsVetoableChange

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

        JFileChooser fileopen = new JFileChooser();
        FileFilter filter = new FileNameExtensionFilter("*.txt", "txt");
        fileopen.addChoosableFileFilter(filter);
        int ret = fileopen.showDialog(this, "Save file");
        try {
            if (ret == JFileChooser.APPROVE_OPTION) {
                Util.exportarTXT(fileopen.getSelectedFile().getCanonicalPath());

            }
        } catch (Exception x) {
        }


    }//GEN-LAST:event_jButton5ActionPerformed
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:



        Mapa m = ((Mapa) jComboBox1.getSelectedItem());
        //System.out.println(m.getPath());
        jLabel5.setIcon(new ImageIcon(m.getPath()));
        for (GraphSpots gs : GestGrahSpot.getInstance().retornarGraphs()) {
            if (((Mapa) jComboBox1.getSelectedItem()).getNro() == gs.getMap().getNro()) {


                Graphics2D g = (Graphics2D) jLabel5.getGraphics();
                g.setColor(gs.getColor());
                g.drawOval(gs.getX() - (gs.getRadio() / 2), gs.getY() - (gs.getRadio() / 2), gs.getRadio(), gs.getRadio());
            }
        }



    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jLabel5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel5MouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 2 && !evt.isConsumed()) {
            if (!GestMapa.getInstance().retornarMapas().isEmpty()) {
                evt.consume();

                Point p = new Point(this.jLabel5.getMousePosition().getLocation());

                //Graphics g = this.jLabel5.getGraphics();

                Color c = Color.red;
                //g.setColor(c);
                //g.drawOval((int) p.getX() - (SliderRadio.getValue() / 2), (int) p.getY() - (SliderRadio.getValue() / 2), SliderRadio.getValue(), SliderRadio.getValue());




                //Recuperamos el Numero de mob
                int nroMob = Integer.parseInt(this.txtNroMob.getText());
                //Recuperamos el Numero del mob guardado en el objeto correspondiente
                String nombreMapa = ((Mapa) this.jComboBox1.getSelectedItem()).getNombre();
                int nroMapa = GestMapa.getInstance().retornarNroMapa(nombreMapa);
                //Recuperamos el raido.
                int radio = this.SliderRadio.getValue();
                //Recuperamos las cordenadas X Y.
                int cordX = (int) p.getX() / 2;
                int cordY = (int) p.getY() / 2;
                //Generamos el random segun limite
                int cordX2 = Util.radomizeXY(cordX, Integer.valueOf(this.txtLimiteRandom.getText()));
                int cordY2 = Util.radomizeXY(cordY, Integer.valueOf(this.txtLimiteRandom.getText()));
                //Recuperamos la direccion
                int dire = Integer.valueOf(this.txtDirec.getText());
                //Recuperamos la cantidad
                int cant = this.SliderCant.getValue();




                //Agregamos el circulo graphico en su respectiva coleccion
                GestGrahSpot.getInstance().cargarNuevoGraph((cordX * 2), (cordY * 2), c, SliderRadio.getValue() / 2, ((Mapa) jComboBox1.getSelectedItem()).getNro());

                //Generamos en nuevo spot y guardamos
                // nroMob, nroMapa, radio, cordX,cordY,cordX2,cordY2, dire,cant
                GestSpots.getInstance().agregarPunto(nroMob, nroMapa, radio, cordX, cordY, cordX2, cordY2, dire, cant);


                //Listamos en la tabla
                jtabelSpots.setModel(Util.listarSpots((DefaultTableModel) this.jtabelSpots.getModel()));

                //Actualizamos los valores de los textfield
                this.lblCantSpots.setText(String.valueOf(GestSpots.getInstance().devolverSpots().size()));
                this.lblCantAgregados.setText(String.valueOf(GestSpots.getInstance().sumarCantMobs()));



                //  Graphics2D g = (Graphics2D) this.jLabel5.getGraphics();
                //  g.setColor(c);
                //  g.drawOval(cordX*2 - (radio / 2), cordY*2 - (radio / 2), radio, radio);

                //Procedemos a dibujar dependiendo del mapa seleccionado
                // Util.repintar(jLabel1, nroMapa);

                for (GraphSpots gs : GestGrahSpot.getInstance().retornarGraphs()) {
                    if (((Mapa) jComboBox1.getSelectedItem()).getNro() == gs.getMap().getNro()) {
                        Graphics2D g = (Graphics2D) this.jLabel5.getGraphics();
                        g.setColor(gs.getColor());
                        g.drawOval(gs.getX() - (gs.getRadio() / 2), gs.getY() - (gs.getRadio() / 2), gs.getRadio(), gs.getRadio());
                    }
                }


            }
            //  JOptionPane.showMessageDialog(this, "Carge los mapas.", "Error al dibujar spot", JOptionPane.ERROR_MESSAGE);

        }

    }//GEN-LAST:event_jLabel5MouseClicked

    private void jLabel5MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel5MouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel5MouseEntered

    private void jLabel5MouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel5MouseMoved
        Point p = new Point(this.jPanel1.getMousePosition().getLocation());
        this.lblCordX.setText(String.valueOf(p.getX() / 2));
        this.lblCordY.setText(String.valueOf(p.getY() / 2));        // TODO add your handling code here:
    }//GEN-LAST:event_jLabel5MouseMoved

    private void jLayeredPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLayeredPane1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jLayeredPane1MouseClicked

    private void formFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusLost
        // TODO add your handling code here:
  
    }//GEN-LAST:event_formFocusLost

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        // TODO add your handling code here:
     
    }//GEN-LAST:event_formWindowGainedFocus

    private void formWindowLostFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowLostFocus
        // TODO add your handling code here:
    
    }//GEN-LAST:event_formWindowLostFocus

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;






                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmSpot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmSpot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmSpot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmSpot.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new FrmSpot().setVisible(true);






                } catch (IOException ex) {
                    Logger.getLogger(FrmSpot.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSlider SliderCant;
    private javax.swing.JSlider SliderRadio;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTable jtabelSpots;
    private javax.swing.JLabel lblCantAgregados;
    private javax.swing.JLabel lblCantMaps;
    private javax.swing.JLabel lblCantMobs;
    private javax.swing.JLabel lblCantSpots;
    private javax.swing.JLabel lblCordX;
    private javax.swing.JLabel lblCordY;
    private javax.swing.JLabel lblRadio;
    private javax.swing.JLabel lvlCantidad;
    private javax.swing.JTextField txtDirec;
    private javax.swing.JTextField txtLimiteRandom;
    private javax.swing.JTextField txtNomMob;
    private javax.swing.JTextField txtNroMob;
    // End of variables declaration//GEN-END:variables
}
